package cn.lyq.card.ui.achievement

import androidx.lifecycle.MutableLiveData
import cn.lyq.card.base.SimpleVM
import cn.lyq.card.data.model.AchievementInfo
import cn.lyq.card.data.src.Result


class AchievementVM : SimpleVM() {

    val dayInfo = MutableLiveData<Result<AchievementInfo>>()
    val monthInfo = MutableLiveData<Result<AchievementInfo>>()
    val allInfo = MutableLiveData<Result<AchievementInfo>>()

    fun refresh(type: Int, date: String) {
        val info = getInfo(type)
        simplePost(info) {
            repository.achievementService.getAchievementInfo(type + 1, date)
        }
    }

    fun getInfo(type: Int): MutableLiveData<Result<AchievementInfo>> {
        return when (type) {
            0 -> dayInfo
            1 -> monthInfo
            2 -> allInfo
            else -> dayInfo
        }
    }
}